<?php
/**
 *   File functions:
 *   Add awaiting news
 *
 *   @name                 : addtext.php                            
 *   @copyright            : (C) 2006 Vallheru Team based on Gamers-Fusion ver 2.5
 *   @author               : thindil <thindil@users.sourceforge.net>
 *   @author               : eyescream <tduda@users.sourceforge.net>
 *   @version              : 1.3
 *   @since                : 22.12.2006
 *
 */

//
//
//       This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// $Id: addtext.php 879 2007-01-23 17:19:03Z thindil $

    $smarty -> assign(array("Pmsubject" => PM_SUBJECT,
        "Pmbody" => PM_BODY,
        "Rmember" => R_MEMBER,
        "Rking" => R_KING,
        "Rstaff" => R_STAFF,
        "Rjudge" => R_JUDGE,
        "Rjudge2" => R_JUDGE2,
        "Rjudge3" => R_JUDGE3,
        "Rlawyer" => R_LAWYER,
        "Rbeggar" => R_BEGGAR,
        "Rbarbarian" => R_BARBARIAN,
        "Rscribe" => R_SCRIBE,
        "Rknight" => R_KNIGHT,
        "Rlady" => R_LADY,
        "Rcount" => R_COUNT,
        "Rcount2" => R_COUNT2,
        "Rredactor" => R_REDACTOR,
        "Rinnkeeper" => R_INNKEEPER,
        "Rprocurator" => R_PROCURATOR,
        "Asend" => A_SEND));


    if (isset ($_GET['step']) && $_GET['step'] == 'send') 
    {
        if (empty ($_POST['body']) || empty($_POST['rank'])) 
        {
            error (EMPTY_FIELDS);
        }
		if ($player -> rank != 'Admin' && $_POST['rank'] == 'Member') error('Nie mozesz!');
        $_POST['subject'] = strip_tags($_POST['subject']);
        $_POST['body'] = strip_tags($_POST['body']);
	$_POST['rank'] = strip_tags($_POST['rank']);
        $strSubject = $db -> qstr($_POST['subject'], get_magic_quotes_gpc());
        $strBody = $db -> qstr($_POST['body'], get_magic_quotes_gpc());
        $strDate = $db -> DBDate($newdate);
	if ($_POST['rank'] == 'Gwardzista') $_POST['rank'] = "Gwardzista' OR 'Kapitan Gwardii";
        $odbio = $db -> Execute("SELECT id FROM players WHERE rank = '".$_POST['rank']."'");
        $gracze = 0;
        while (!$odbio -> EOF) 
        {
            $db -> Execute("INSERT INTO mail (sender, senderid, owner, subject, body, date) VALUES('".$player -> user."','".$player -> id."',".$odbio -> fields['id'].", ".$strSubject.", ".$strBody.", ".$strDate.")") or error(E_DB);
            $gracze = $gracze + 1;
            $odbio -> MoveNext();
        }
            $db -> Execute("INSERT INTO mail (sender, senderid, owner, subject, body, date) VALUES('".$player -> user."','".$player -> id."',1, ".$strSubject.", ".$strBody.", ".$strDate.")") or error(E_DB);
         $odbio -> Close();
        error (YOU_SEND_PM." ".$gracze." ".PLAYERS_A);
    }
?>
